<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../../header.jsp"%>
<script type="text/javascript">
var detailValidator;
var passwordValidator;

function selectOrganization() {
	$.openDialog("#dialog",
			{height:450,
			width:330,
			loadPage:ctx+"/biz/system/organ/query.jsp",
			title:"选择组织机构"},
			function(data) {
				$("#userOrgan").data("id",data.data("id"));
				$("#userOrgan").val(data.data("name"));
			});
}

function saveDetail() {
	if (!detailValidator.form()) {
		return;
	}
	doSaveDetail();
}

function doSaveDetail() {
	var data = {
			id : $("#userId").val(),
			name : $("#userName").val(),
			account : $("#userAccount").val(),
			mobile : $("#userMobile").val(),
			organId : $("#userOrgan").data("id"),
			description : $("#userDesc").val()
		};
	
	$.ajax({
		type: "POST",
		url: "save.json",
		data: data,
		success: saveSucceedCallback,
		error:function(message){
			$.alert(message);
		}  
	});
}

function changePassword() {
	if (!passwordValidator.form()) {
		return;
	}
	doChangePassword();
}

function doChangePassword() {
	var data = {
			id : $("#userId").val(),
			newPassword : $("#userNewPassword").val(),
			newPasswordRetry : $("#userNewPasswordRetry").val()
		};
	
	$.ajax({
		type: "POST",
		url: "../admin/changePassword.json",
		data: data,
		success: saveSucceedCallback,
		error:function(message){
			$.alert(message);
		}  
	});
}

function saveSucceedCallback(data) {
	if (!data.succeed) {
		$.notice(data.message);
		return;
	}

	$("#userId").val(data.data.id);
	$.notice("保存成功！");
}

$(document).ready(function() {
	$("#tabs").tab("show");
	$("#userOrgan").data("id",$("#userOrganId").val());

	detailValidator = $("#detailForm").validate({
		rules: {
			userName:{required:true},
			userAccount:{required:true}
		},
		messages:{
			userName:{required:"请输入用户名"},
			userAccount:{required:"请输入用户登录账号名"}
		}
	});

	passwordValidator = $("#passwordForm").validate({
		rules: {
			userNewPassword:{required:true},
			userNewPasswordRetry:{required:true}
		},
		messages:{
			userNewPassword:{required:"请输入密码"},
			userNewPasswordRetry:{required:"请再次输入密码"}
		}
	});

	
	
});

</script>

<div class="span9">



<div class="page-header">
<div class="cms_toolbar">
<ul>
<li><a href="#" onclick="deleteIt()" class="btn"><i class="icon-user"></i>角色绑定</a>
</li>
</ul>
</div>
<h2>协作人员管理</h2>
</div>

<div id="tabs">

<ul class="nav nav-tabs">
<li class="active"><a href="#detailPanel" data-toggle="tab">基本信息</a>
</li>
<li><a href="#passwordPanel" data-toggle="tab">修改密码</a>
</li>
</ul>

<div class="tab-content">
<div id="detailPanel" class="tab-pane fade in active">

<form id="detailForm" class="form-horizontal">
<input type="hidden" id="userId" value="${data.id}">
<input type="hidden" id="userOrganId" value="${data.organId}">
	<fieldset>
	<div class="control-group">
		<label for="userName"  class="control-label">姓名：</label>
		<div class="controls">
		<input type="text" id="userName" name="userName" class="required" value="${data.name}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userAccount" class="control-label">登录账号：</label>
		<div class="controls">
		<input type="text" id="userAccount" name="userAccount" class="required" value="${data.account}"> <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userMobile" class="control-label">移动电话：</label>
		<div class="controls">
		<input type="text" id="userMobile" name="userMobile" value="${data.mobile}">
		</div>
	</div>
	<div class="control-group">
		<label for="userExecOrgan" class="control-label">所属单位：</label>
		<div class="controls">
		<input type="text" id="userOrgan" readonly="readonly" name="userOrgan" value="${data.organName}"><input type="button" class="btn" value="选择" onclick="selectOrganization()">
		</div>
	</div>
	<div class="control-group">
		<label for="userDesc" class="control-label">描述：</label>
		<div class="controls">
		<textarea id="userDesc" name="userDesc">${data.description}</textarea>
		</div>
	</div>
	<div class="form-actions">
		<a href="#" class="btn btn-primary" onclick="saveDetail()"><i class="icon-ok"></i>保存</a>
	</div>
	</fieldset>
</form>

</div>

<div id="passwordPanel" class="tab-pane fade">
<form id="passwordForm"  class="form-horizontal">
	<fieldset>
	<div class="control-group">
		<label for="userNewPassword" class="control-label">新密码：</label> 
		<div class="controls">
		<input type="password" id="userNewPassword" class="required"  name="userNewPassword" > <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="control-group">
		<label for="userNewPasswordRetry" class="control-label">新密码(再输入一次)：</label>
		<div class="controls">
		<input type="password" id="userNewPasswordRetry" class="required"  name="userNewPasswordRetry" > <span class="cms_color_required">*</span>
		</div>
	</div>
	<div class="form-actions">
		<a href="#" class="btn btn-primary" onclick="changePassword()"><i class="icon-ok"></i>保存</a>
	</div>

	</fieldset>
</form>
</div>
</div>
</div>

</div>
<%@ include file="../../../footer.jsp"%>